﻿using System;
using System.Collections.Generic;
using System.Text;
using NExt.grid;
using NExt.data;
using NExt.Core.Model.Base;

namespace NExt.UI.Browse.Data
{
    public class GridBrowsePresenter: DataBrowsePresenter
    {
        //TODO: reader and record can not be add as variable...
        //FIX it..
        public Store store;
        public GridPanel gridPanel;

        protected IScript onGridDoubleClick;


        protected override void FormBuildComponents()
        {
            base.FormBuildComponents();
            store = new Store();
            gridPanel = new GridPanel();
        }

        protected override void FormInitializeEvents()
        {
            base.FormInitializeEvents();
            onGridDoubleClick = fireOpen;
        }


        protected override void FormInitializeComponents()
        {
            base.FormInitializeComponents();

            DataReader reader = BuildReader();
            ColumnModel columnModel = BuildColumnModel();

            store.reader = reader;
            gridPanel.border = false;
            gridPanel.ds = store;
            gridPanel.cm = columnModel;
            gridPanel.viewConfig = new NExt.grid.GridView() { forceFit = true };
            gridPanel.extended = new { anchor = "100% 95%" };
            gridPanel.listeners.dblclick = onGridDoubleClick;

            items.Add(gridPanel);
        }

        protected virtual ColumnModel BuildColumnModel()
        {
            return new ColumnModel();
        }

        protected virtual DataReader BuildReader()
        {
            return new DataReader();
        }
    }
}
